import requests
import execjs

EncKey = execjs.compile(open('source.js', 'r', encoding='utf-8').read()).call('getResCode')
# print(EncKey)
headers = {
    'Accept': '*/*',
    'Accept-EncKey': EncKey,
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Cookie': 'MALLSSID=6534777A49616856482F4B717A337278646E6D33357754733667794957527336304E4762523477326F2F6F545158364569654A56463175667762462F54755534',
    'Origin': 'https://webapi.cninfo.com.cn',
    'Pragma': 'no-cache',
    'Referer': 'https://webapi.cninfo.com.cn/',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
    'X-Requested-With': 'XMLHttpRequest',
    'sec-ch-ua': '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}

data = {
    'tdate': '2024-04-08',  # 日期 为'xxxx-xx-xx'格式 'xxxx-x-x'格式不行会报错
    'market': 'SZE',
}

response = requests.post('https://webapi.cninfo.com.cn/api/sysapi/p_sysapi1007', headers=headers, data=data)
# print(response.json())
for i in response.json()['records']:
    print(i)
